package top.stacktrace.util;

import lombok.Data;

@Data
public class Result {
    public static final int SUCC = 0;
    public static final int FAILED = 1;

    private int code = SUCC;
    private String msg;
    private Object data;

    public Result(int code,String msg,Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result ok(Object data){
        return new Result(SUCC,"",data);
    }

    public static Result fail(String msg){
        return new Result(FAILED,msg,null);
    }

    public static Result fail(int code,String msg){
        return new Result(code,msg,null);
    }

    public static Result get(boolean result,String msg,Object data){
        if(result){
            return ok(data);
        }
        return fail(msg);
    }

}
